package cn.jilian.front.web;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import cn.jilian.common.domain.R;
import cn.jilian.entity.Order;
import cn.jilian.front.util.SessionUtil;
import cn.jilian.trans.bizz.dto.TransOrder;
import cn.jilian.trans.bizz.service.OrderService;
import io.swagger.annotations.ApiOperation;

@Controller
@RequestMapping("/supplier")
public class SupplierController {
	
	@Autowired
	private OrderService orderService;
	
	@ApiOperation(value="填写货源单界面")
	@GetMapping("/order/fill.html")
	public ModelAndView fillOrderPage() {
		ModelAndView mv=new ModelAndView("supplier/order_fill.html");
		return mv;
	}
	
	@ApiOperation(value="提交货源单")
	@PostMapping("/order/submit")
	public R submitOrder(@Valid @RequestParam Order order,HttpSession session) {
		Long unid=SessionUtil.getUnitId(session);
		order.setFid(unid);
		int r=orderService.save(order);
		return r>0?R.ok:R.fail;
	}
	
	@ApiOperation(value="查询待处理货源单列表")
	@PostMapping("/order/list")
	public Page<TransOrder> queryUnHandledOrder(Pageable page){
		
		return  null;
	}
	
	@ApiOperation(value="选择指定报价单生成待签订物流合同")
	@PostMapping("/contract/{postId}")
	public R createContract(@PathVariable(name="postId")Long postId,HttpSession session) {
		return R.ok;
	}

}
